package tinyGA;

import java.util.Map;
import java.util.HashMap;

public class TS {

	private Map<String, TipoElem> tablaTipo;
	private Map<String, Integer> tablaDir;

	public TS() {
		tablaDir = new HashMap<String, Integer>();
		tablaTipo = new HashMap<String, TipoElem>();
	}

	private TS(Map<String, TipoElem> tTipo, Map<String, Integer> tDir) {
		this.tablaDir = tDir;
		this.tablaTipo = tTipo;
	}

	public TS aniadeLex(String lex, TipoElem tipo, Integer dir) {
		TS tSimb = new TS(new HashMap<String, TipoElem>(tablaTipo),
				new HashMap<String, Integer>(tablaDir));
		tSimb.tablaDir.put(lex, dir);
		tSimb.tablaTipo.put(lex, tipo);
		return tSimb;
	}

	public TS borraLex(String lex) {
		TS tSimb = new TS(new HashMap<String, TipoElem>(tablaTipo),
				new HashMap<String, Integer>(tablaDir));
		tSimb.tablaTipo.remove(lex);
		tSimb.tablaDir.remove(lex);
		return tSimb;
	}

	public boolean estaEn(String lex) {
		return tablaTipo.containsKey(lex) && tablaDir.containsKey(lex);
	}

	public TipoElem tipoDe(String lex) {
		return tablaTipo.get(lex);
	}

	public int dirDe(String lex) {
		return tablaDir.get(lex);
	}

	public String toString() {
		return tablaTipo.toString() + tablaDir.toString();
	}
}
